package com.my.chapter18;

import java.io.*;

public class practice28  implements Externalizable{
    public practice28(){
        System.out.println("BlipCheck Constructor");
    }
    public void writeExternal(ObjectOutput out)
            throws IOException {
        System.out.println("BlipCheck.writeExternal");
    }
    public void readExternal(ObjectInput in)
            throws IOException, ClassNotFoundException {
        System.out.println("BlipCheck.readExternal");
    }

    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Blips.main(args);
    }
}

class Blip1 implements Externalizable {
    public Blip1() {
        System.out.println("Blip1 Constructor");
    }
    public void writeExternal(ObjectOutput out)
            throws IOException {
        System.out.println("Blip1.writeExternal");
    }
    public void readExternal(ObjectInput in)
            throws IOException, ClassNotFoundException {
        System.out.println("Blip1.readExternal");
    }
}


class Blips {
    // Throw exceptions to console:
    static String path = ".\\src\\com\\my\\chapter18\\";
    public static void main(String[] args)
            throws IOException, ClassNotFoundException {
        System.out.println("Constructing objects:");
        Blip1 b1 = new Blip1();
        practice28 b2 = new practice28();
        ObjectOutputStream o =
                new ObjectOutputStream(
                        new FileOutputStream(path + "Blips.out"));
        System.out.println("Saving objects:");
        o.writeObject(b1);
        o.writeObject(b2);
        o.close();
        // Now get them back:
        ObjectInputStream in =
                new ObjectInputStream(
                        new FileInputStream(path + "Blips.out"));
        System.out.println("Recovering b1:");
        b1 = (Blip1)in.readObject();
        // OOPS! Throws an exception:
        System.out.println("Recovering b2:");
        b2 = (practice28)in.readObject();
    }
}
